package com.wly.box2d
{
	import com.wly.ui.gamescene.IHitObject;
	
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.geom.Point;
	
	import Box2D.Collision.Shapes.b2Shape;
	import Box2D.Common.Math.b2Vec2;
	import Box2D.Dynamics.b2Body;
	import Box2D.Dynamics.b2BodyDef;
	import Box2D.Dynamics.b2FixtureDef;
	import Box2D.Dynamics.b2World;

	public class BoxItem
	{
		public var density:Number;	//gratter than 0
		public var friction:Number;	//between 0 and 1
		public var restitution:Number; //usual between 0 and 1

		public var bX:Number;
		public var bY:Number;
		public var bW:Number;
		public var bH:Number;
		public var b2Type:int;
		public var boxBody:b2Body;
		public var angle:Number;
		public var viewObj:DisplayObject;
		public var itemStat:int = 0;
		
		public var isSensor:Boolean = false;
		
		public function BoxItem()
		{
			angle 		= 0;
			b2Type 	    = b2Body.b2_staticBody;
			density     = 0.3;
			friction    = 0;
			restitution = 1;
		}
		
		public function initWithSprite(obj:Sprite, isSensor:Boolean=false, itemStat:int=0):void
		{
			if(!obj)
			{
				return;
			}
			
			bX = obj.x;
			bY = obj.y;
			bW = obj.width;
			bH = obj.height;
			viewObj = obj;
			this.isSensor = isSensor;
			this.itemStat = itemStat;
		}
		
		//return false if need destroy
		public function onHit(hitItem:DisplayObject, hitPos:Point):Boolean
		{
			var hitObj:IHitObject = viewObj as IHitObject;
			if(hitObj)
			{
				return hitObj.onHit(hitItem, hitPos);
			}
			
			return true;
		}
	}
}